<?php
/**
 * Created by PhpStorm.
 * User: brain
 * Date: 2016/3/24
 * Time: 11:45
 */

namespace App\Utils;

use App\C5Client\C5Client;
use App\Kids\Caches\Companies;

class SMSUtils
{

    public static function sendSms($mobiles, $content, $companyId = "")
    {
        $prefix = env("SMS_PREFIX", "【邻童网】");
        if (!empty($companyId)) {
            $company = Companies::findCompany($companyId);
            if (!empty($company)) {
                $prefix = "【" . $company["brief_name"] . "】";
            }
        }
        $content = $prefix . $content;
        if (is_array($mobiles)) {
            $mobiles = implode(",", $mobiles);
        }
        $smsApiRemoteUserId = env("sms_api_remote_user_id", "anju");
        $smsApiAccessSalt = env("sms_api_access_salt", "XMANJU-2016-AJYYXT");
        $smsApiBaseUrl = env("sms_api_base_url", "http://115.28.151.208:9080/service/utf-8/");
        $client = new C5Client($smsApiRemoteUserId, $smsApiAccessSalt);
        $client->add_parameter("encoding", "utf8");
        $client->add_parameter("mobiles", $mobiles);
        $client->add_parameter("smsContent", $content);
        $client->setBaseUrl($smsApiBaseUrl);
        $client->setUrl("sms/send");
        $client->post();
        return $client->getResultArray();
    }

}